import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpClient {

    private Socket socket = null;

    public TcpClient(String ServerIp,int ServerPort) throws IOException {

        socket = new Socket(ServerIp,ServerPort);
    }
    public void start(){
        try(InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream()){
            Scanner scanner = new Scanner(inputStream);
            Scanner scannerin = new Scanner(System.in);
            PrintWriter printWriter = new PrintWriter(outputStream);
            while (true){
                System.out.print("-> ");
                String request = scannerin.next();

                printWriter.println(request);
                printWriter.flush();
                if(!scanner.hasNext()){
                    break;
                }
                String response = scanner.next();

                System.out.println(response);
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException {
        TcpClient tcpClient =new TcpClient("127.0.0.1",8888);
        tcpClient.start();
    }
}
